package cn.virens.dd.simple.strategy;

import java.util.Date;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.date.DateUtil;
import cn.virens.dd.simple.AbstractStrategy;
import cn.virens.dd.simple.value.StrategyValueByLatLng;

/**
 * 日出时间（关灯控制策略）
 * 
 * @author Virens
 */
public class StrategyByLatLngSunrise extends AbstractStrategy<StrategyValueByLatLng> {
	private final Integer offset;

	public StrategyByLatLngSunrise(Object offset) {
		this.offset = Convert.toInt(offset, 0);
	}

	public Integer getOffset() {
		return offset;
	}

	@Override
	public void close() throws Exception {

	}

	@Override
	protected boolean filter0(StrategyValueByLatLng value) {
		return before(sunrise(value), DateUtil.date());
	}

	private Date sunrise(StrategyValueByLatLng value) {
		return offset(value.getSunrise(), offset);
	}

	private static Date offset(Date time, Integer offset) {
		return DateUtil.offsetMinute(time, offset);
	}

}
